import 'package:flutter/material.dart';

class NavigationUtils {
  
  static Future<T?> navigateTo<T>(
    BuildContext context,
    String routeName,
    {Map<String, dynamic>? arguments}
  ) async {
    return Navigator.pushNamed<T>(
      context,
      routeName,
      arguments: arguments,
    );
  }

  
  static Future<T?> replaceWith<T>(
    BuildContext context,
    String routeName,
    {Map<String, dynamic>? arguments}
  ) async {
    return Navigator.pushReplacementNamed<T, dynamic>(
      context,
      routeName,
      arguments: arguments,
    );
  }

  
  static Future<T?> navigateAndClearStack<T>(
    BuildContext context,
    String routeName,
    {Map<String, dynamic>? arguments}
  ) async {
    return Navigator.pushNamedAndRemoveUntil<T>(
      context,
      routeName,
      (route) => false,
      arguments: arguments,
    );
  }

  
  static void goBack(BuildContext context, {dynamic result}) {
    Navigator.pop(context, result);
  }

  
  static Future<T?> showBottomSheet<T>(
    BuildContext context,
    Widget child,
    {bool isScrollControlled = false}
  ) async {
    return showModalBottomSheet<T>(
      context: context,
      builder: (context) => child,
      isScrollControlled: isScrollControlled,
    );
  }

  
  static Future<bool?> showConfirmationDialog(
    BuildContext context,
    String title,
    String content,
    {String confirmText = '确认', String cancelText = '取消'}
  ) async {
    return showDialog<bool>(
      context: context,
      builder: (context) => AlertDialog(
        title: Text(title),
        content: Text(content),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context, false),
            child: Text(cancelText),
          ),
          TextButton(
            onPressed: () => Navigator.pop(context, true),
            child: Text(confirmText),
          ),
        ],
      ),
    );
  }
}
